#include<stdio.h>
#include<stdlib.h>

#define queueSize 10  // 队列的长度
// 循环队列的实现

typedef struct 
{
    int* base;  //动态分配的内存空间
    int head;   // 头指针
    int tail;   // 尾指针
}SqQueue;

SqQueue initQueue()
{
    SqQueue queue;
    queue.base=(int*) malloc(queueSize*sizeof(int));
    
    for(int i=0;i<queueSize;i++)
    {
        queue.base[i]=-1;
    }
    queue.head=0;
    queue.tail=0;

    return queue;
}

int emptyQueue(SqQueue* queue)
{
    if(queue->tail==queue->head)
        return 1;
    else
        return 0;
}

void joinQueue(SqQueue* queue,int data)
{
    queue->base[queue->tail]=data;
    queue->tail=(queue->tail+1)%queueSize;
}

int OutQueue(SqQueue* queue)
{
    int temp=-1;
    if(!emptyQueue(queue))
    {
        temp=queue->base[queue->head];
        queue->head=(queue->head+1)%queueSize;
    }
    return temp;
}

void main()
{
    SqQueue queue=initQueue();
    joinQueue(&queue,1);
    joinQueue(&queue,2);
    joinQueue(&queue,3);
    joinQueue(&queue,4);
    printf("%d\n",OutQueue(&queue));
    printf("%d\n",OutQueue(&queue));
    printf("%d\n",OutQueue(&queue));
    printf("%d\n",OutQueue(&queue));

}